// Copyright 2021 Guoyoko. All Rights Reserved.

#pragma once

#include "Slate/SSWDetailSingleItemRow.h"
#include "Core/SWDetailNode.h"
#include "Style/SWCoreStyle.h"


void SSWDetailSingleItemRow::Construct(const FArguments& InArgs, TSharedRef<FSWDetailNode> InOwnerTreeNode, const TSharedRef<STableViewBase>& InOwnerTableView)
{
	OwnerTreeNode = InOwnerTreeNode;

	this->ChildSlot
	[
		SNew(SHorizontalBox)

		+ SHorizontalBox::Slot()
		.AutoWidth()
		.HAlign(HAlign_Right)
		.VAlign(VAlign_Fill)
		[
			SNew(SExpanderArrow, SharedThis(this))
		]

		+ SHorizontalBox::Slot()
		.FillWidth(1)
		[
			SNew(SBorder)
			.BorderImage(this, &SSWDetailSingleItemRow::GetBorderImage)
			.Padding(FMargin(0.f))
			[
				SNew(SBox)
				.VAlign(VAlign_Center)
				.HeightOverride(DetailWidgetConstants::DetailItemHeight)
				.Padding(DetailWidgetConstants::DetailItemPadding)
				[
					OwnerTreeNode.Pin()->GetNodeWidget()
				]
			]
		]
	];

	STableRow< TSharedPtr< FSWDetailNode > >::ConstructInternal(
		STableRow::FArguments(),
		InOwnerTableView
	);
}

const FSlateBrush* SSWDetailSingleItemRow::GetBorderImage() const
{
	if (IsHovered())
	{
		return FSWCoreStyle::Get().GetBrush("DetailsView.Item_Hovered");
	}
	else
	{
		return FSWCoreStyle::Get().GetBrush("DetailsView.Item");
	}

	return nullptr;
}

